package main

import (
	"context"
	"fmt"
	stdlog "log"
	"web-service-demo/log"
	"web-service-demo/registry"
	"web-service-demo/service"
)

func main() {
	//指定日志文件
	log.Run("./distributed.log")

	//设置服务URL
	host, port := "localhost", "4000"
	serviceAddress := fmt.Sprintf("http://%s:%s", host, port)

	//准备注册信息
	r := registry.Registration{
		ServiceName:      "LogService",
		ServiceURL:       serviceAddress,
		RequiredServices: make([]string, 0), //它没有依赖服务
		ServiceUpdateURL: serviceAddress + "/services",
		HeartbeatURL:     serviceAddress + "/heartbeat",
	}

	//启动服务
	ctx, err := service.Start(context.Background(), host, port, r, log.RegisterHandlers)
	if err != nil {
		stdlog.Fatalln(err)
	}

	//等待程序关闭
	<-ctx.Done()
	fmt.Println("Shutting down log service.")
}
